package operation;

import book.Book;
import book.Bookshelf;

import java.util.Scanner;

public class ReturnOperation implements IOperation{
    public void work(Bookshelf bookshelf) {
        System.out.println("归还图书");
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入要归还的书名");
        String name = scanner.nextLine();

        int cur = bookshelf.getUsedSize();
        for (int i = 0; i < cur; i++) {
            Book book = bookshelf.getBook(i);
            if (name.equals(book.getName())) {
                //查看归还状态
                if (book.isBorrowed()) {
                    book.setBorrowed(false);
                    System.out.println("归还成功");

                } else {
                    System.out.println("已被归还，无法归还");
                }
                return;
            }
        }

        //没有找到
        System.out.println("没有此书");
    }
}